import {BannerList,VerificationList,VerifycorrectList,RegisteredaccountList,LoginaccountList,
        DailyrecommendedsongList,ExclusivebroadcastentryList,RecommendnewmusicList,RecommendedmvList,
        Recommendedsongsoftheday
} from '@/api/api'
import { Message } from 'element-ui';

const state= {
  //获取到轮播图的数据
  bannerlist: {},
  //注册账号
  loginlist:'',
  //登录账号
  Loginaccount:'',
  informationlist:{},
  //获取每日推荐歌单列表
  DailyRecommendedsonglist:[],
  //独家放送列表
  castentryList:[],
  //最新音乐
  newmusiclist:[],
  //推荐mv
  recommendnewmusiclist:[],
  //获取每日歌曲
  dailySongs:[]
};
const mutations= {
  //获取到轮播图的数据
  BANNERLIST(state,bannerlist){
      state.bannerlist = bannerlist
  },
  //注册账号
  COUNTLIST(state,loginlist){
    state.loginlist = loginlist
  },
  //登录账号
  LOGINLIST(state,Loginaccount){
    state.Loginaccount = Loginaccount
  },
  INFORMATION(state,informationlist){
    state.informationlist = informationlist
  },
  //获取每日推荐歌单
  COMMENDEONGLIST(state,DailyRecommendedsonglist){
    state.DailyRecommendedsonglist = DailyRecommendedsonglist
  },
  //独家放送入口列表
  EXCLUSIVEBROAD(state,castentryList){
    state.castentryList = castentryList
  },
  //获取最新音乐
  NEWMUSICLIST(state,newmusiclist){
    state.newmusiclist = newmusiclist
  },
  //推荐mv
  RECOMMENDNEWMUSSICLIST(state,recommendnewmusiclist){
      state.recommendnewmusiclist = recommendnewmusiclist
  },
  //获取每日推荐歌曲
  RECOMMENDESONGFTHEDAY(state,dailySongs){
    state.dailySongs = dailySongs
  }
};
const actions= {
  //获取到轮播图的数据
 async getBannerList({commit}){
  let request = await BannerList()
  if(request.status==200){
    commit('BANNERLIST',request.data.banners)
  }
  },
  //发送验证码
  async getVerificationList({commit},data){
   let request =await VerificationList(data)
   console.log(request);
   if(request.data.code!==200){   
  Message({message: request.data.message, duration: 1000 })
   }
  },
  //验证验证码是否正确
  async getVerifycorrectList({commit},{phone,captcha}){
  let request = await VerifycorrectList({phone,captcha})
  if(request.data.code!==200){    
  Message({message: '验证码错误！！！', duration: 1000,type: 'warning' })
  }
  },
  //注册账号
  async getRegisteredaccountList({commit},{captcha,phone,password,nickname}){
  let request = await RegisteredaccountList({captcha,phone,password,nickname})
  console.log(request);
  if(request.data.code==200){
    Message({message:'注册成功',duration:1000,type: 'success'})
    commit('COUNTLIST',1)
  }else{
    Message({message:request.data.message, duration: 1000 })
  }
  },
  //登录账号
  async getLoginaccountList({commit},{phone,password}){
   let request = await LoginaccountList({phone,password})
   console.log(request);
   if(request.data.code==200){
    //把数据存储到本地存储中
    localStorage.setItem('token',request.data.token)
    localStorage.setItem('cookie',request.data.cookie)
    localStorage.setItem('loginType',request.data.loginType)
    localStorage.setItem('nickname',request.data.profile.nickname)
    localStorage.setItem('avatarUrl',request.data.profile.avatarUrl)
    
    Message({message:'登录成功',duration:1000,type: 'success'})
    commit('LOGINLIST',2)
    commit('INFORMATION',request.data)
   }else{
    Message({message:request.data.msg,duration:1000,type: 'warning'})
   }
  },
  //获取每日推荐歌单
 async getDailyrecommendedsongList({commit}){
  let request = await DailyrecommendedsongList()
  if(request.data.code==200){
    commit('COMMENDEONGLIST',request.data.recommend)
  }else{
    Message({message:'推荐歌单获取失败',duration:2000,type:'warning'})
  }
  },
  //独家放送（入口列表）
  async getExclusivebroadcastentryList({commit}){
   let request = await ExclusivebroadcastentryList()
   if(request.data.code==200){
    commit('EXCLUSIVEBROAD',request.data.result)
   }
  },
  //最近新音乐
 async getRecommendnewmusicList({commit},limit){
   let request = await RecommendnewmusicList(limit)
   if(request.data.code==200){
    commit('NEWMUSICLIST',request.data.result)
   }
  },
  //推荐mv
 async getRecommendedmvList({commit}){
  let request = await RecommendedmvList()
  if(request.data.code==200){
    commit('RECOMMENDNEWMUSSICLIST',request.data.result)
  }
  },
  //获取每日推荐歌曲
 async getRecommendedsongsoftheday({commit}){
  let request = await Recommendedsongsoftheday()
  console.log(request);
  if(request.data.code==200){
    commit('RECOMMENDESONGFTHEDAY',request.data.data.dailySongs)
  }
  }
};
const getters= {
};
export default {
  state,
  mutations,
  actions,
  getters
}